var hasFileToUpload = false;

_addCommonFileListener('#uploadFile01', function(file) {
	$('#file01').text(file.name);
	hasFileToUpload = true;
});

_addCommonFileListener('#uploadFile02', function(file) {
	$('#file02').text(file.name);
	hasFileToUpload = true;
});

_addCommonFileListener('#uploadFile03', function(file) {
	$('#file03').text(file.name);
	hasFileToUpload = true;
});

_addCommonFileListener('#uploadFile04', function(file) {
	$('#file04').text(file.name);
	hasFileToUpload = true;
});

_addCommonFileListener('#uploadFile05', function(file) {
	$('#file05').text(file.name);
	hasFileToUpload = true;
});

$(function(){ 
	$("#btnOK").click(function() {
		var loginedUser = getLoginedUser();
		pageParam.staffId = loginedUser.staffId ;
		pageParam.staffName = loginedUser.staffName;
		pageParam.createTime = loginedUser.createTime;
		pageParam.leaseType = parseInt($('#leaseType').val());
		pageParam.leaseStatus = 1;
		pageParam.totalFee = pageParam.totalMoney;
		pageParam.payWay = parseInt($('input:radio[name="payWay"]:checked').val());
		
		save_basic(path+'/lease/save', {lease:pageParam}, function(response) {
			if(response.code=='200') {
				if(hasFileToUpload==false) {
					var url = '5-1-2ywrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
					window.open(url);
				}else {
					var options = {  
						url: path+'/accessory/uploadFiles?id='+response.data[0].leaseId,
						type : "post",  
						dataType : 'json',
						
						//提交前处理 
						beforeSubmit: function() {
						},
						
						//处理完成 
						success: function(response_success) {
							if(response_success.code=='200') {
								var url = '5-1-2ywrent-3.html?pageParam=' + encodeURIComponent(JSON.stringify(pageParam));
								window.open(url);
							}else {
								alert('文件提交失败');
							}
						}
					};
					
					$('#uploadFileForm').ajaxSubmit(options);
				}
			}else {
				alert('数据提交失败');
			}
		});
	});
});